package com.yfeng.common.filter;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LoginFilter implements Filter {

	private static final Log log = LogFactory.getLog(LoginFilter.class);
	private String loginPage = "";

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	/*
	 * 过滤角色的访问页面
	 * 
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 * javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
			throws IOException, ServletException {
		HttpServletRequest hreq = (HttpServletRequest) req;
		HttpServletResponse hres = (HttpServletResponse) res;

		String currentUrl = hreq.getRequestURI();
		log.info("进入:" + currentUrl);
//		if (!currentUrl.startsWith("/stock/admin/")
//				&& !currentUrl.equals("/index.jsp")
//				&& !currentUrl.equals("/index.do")
//				&& !currentUrl.equals("/authImg.do")
//				&& !currentUrl.equals("/tologin.do")
//				&& !currentUrl.equals("/mainframePage.do")
//				&& !currentUrl.equals("/left.jsp")
//				&& !currentUrl.equals("/stock/mystocklistpage.do")
//				&& !currentUrl.equals("/top.jsp")
//				&& !currentUrl.equals("/stock/stocklistpage.do")) {
//			if (hreq.getSession().getAttribute("user4sess") == null) {
//				hreq.setCharacterEncoding("UTF-8");
//				hres.setContentType("text/html;charset=UTF-8");
//				PrintWriter write = hres.getWriter();
//				write.print("<script>alert('请先登录!');</script>");
//				hres.sendRedirect("/index.jsp");
//				return;
//			}
//		} else
			fc.doFilter(req, res);

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		log.info("===============启动登陆过滤器===================");

	}

}
